﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    class AcceptFriendsRequestAction : AuthPostAction<Params.AcceptFriendsRequestParams,
        Results.AcceptFriendsRequestResult>
    {
        protected override ActionResult<Results.AcceptFriendsRequestResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            Params.AcceptFriendsRequestParams opParams)
        {
            ServiceResult<UserRelation> serviceResult = new FriendsService().AcceptRequest(context.AccountId,
                opParams.TargetUserId);

            Results.AcceptFriendsRequestResult actionResult = new Results.AcceptFriendsRequestResult();
            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {
                return new ActionResult<Results.AcceptFriendsRequestResult>(true, serviceResult.ErrorCode, 
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<Results.AcceptFriendsRequestResult>(false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
